﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using _3TierDemo.DTO;
namespace _3TierDemo.DAL
{
    class SVDAO : CommonDAO
    {
               public SVDAO()
            : base()
        { }
        public DataTable getAll()
        {
            string strSelect = "select * from tblsv";
            return execSelect(strSelect);
        }
        public SVDTO getByID(int id)
        {
            string strSelect = "select * from tblsv where ma =" + id.ToString();
            DataTable dt = new DataTable();
            dt = execSelect(strSelect);
            //map vao doi tuong
            SVDTO obj = new SVDTO();
            obj.Ma = Convert.ToInt32(dt.Rows[0][0]);
            obj.Ten = dt.Rows[0][1].ToString();
            obj.Tuoi =Convert.ToInt32( dt.Rows[0][2]);
            obj.MaLop = Convert.ToInt32(dt.Rows[0][3]);
            return obj;

        }
        public bool insert(SVDTO obj)
        {
            string strQuery = "insert into tblsv values ('" + obj.Ten + "'," + obj.Tuoi + "," + obj.MaLop + ")";
            return execNonQuery(strQuery);

        }
        public bool update(SVDTO obj)
        {
            string strQuery = "update tblsv set ten='" + obj.Ten + "',tuoi=" + obj.Tuoi + ",maLop=" + obj.MaLop + " where ma=" +obj.Ma;
            return execNonQuery(strQuery);
        }
        public bool deleteByID(int id)
        {
            string strQuery = "delete from tblsv where ma=" + id.ToString();
            return execNonQuery(strQuery);
        }
    }
}
